/**
 * 
 */
package command;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;



/**
 * Contains a timer checking if there is a new command in the server every half a second.
 * @author Qw4z1
 *
 */
public class ServerReader implements ActionListener{

	private static ServerReader me;
	private Timer timer = new Timer(500,this);
	private String oldString = "^^";
	
	public static ServerReader getInstance(){
		if(me == null)
			me = new ServerReader();
		return me;
	}
	public ServerReader(){
	}

	
	public void startTimer(){
		timer.start();
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(!oldString.equals( CommandBroadcaster.getCommand()) ){
			oldString=CommandBroadcaster.getCommand();
			CommandReciever.decodeAndExecute(oldString);
		}
	}
	

	

}
